#ifndef MESSAGEDISPATCHER_H
#define MESSAGEDISPATCHER_H

class Message;
class MessageListener;

class QUINCE_CORE_EXPORT MessageDispatcher : public QObject
{
    Q_OBJECT
public:
    MessageDispatcher() = default;
    virtual ~MessageDispatcher();

    virtual void dispatch(const Message& msg);

    virtual void subscribe(const string &msgCode, MessageListener* listener);
    virtual void unsubscribe(const string &msgCode, MessageListener* listener);

    MessageListener* getListener(const string &msgCode) const;
Q_SIGNALS:
    void dispatched(const Message &);
private:
    Q_DISABLE_COPY(MessageDispatcher)

    typedef list<MessageListener*> ListenerList;
    typedef map<string, ListenerList> ListenerMap;

    ListenerMap m_listener;
    ListenerList m_catchAllListeners;
};

#endif // MESSAGEDISPATCHER_H
